module.exports = function ($scope, $state, $resource, $modal, toaster, $stateParams) {
	$scope.myKeyup = function (e) {
		//IE 编码包含在window.event.keyCode中，Firefox或Safari 包含在event.which中
		var keycode = window.event ? e.keyCode : e.which;
		if (keycode == 13) {
			$scope.loadlist();
		}
  };
	/* 分页
   * ========================================= */
  $scope.maxSize = 5;            //最多显示多少个按钮
  $scope.bigCurrentPage = 1;      //当前页码
  $scope.itemsPerPage = 10; 
  $scope.searchform = {};
	$scope.loadlist = function () {
    var para = {
        pageNo:$scope.bigCurrentPage, 
        pageSize:$scope.itemsPerPage
    };
    para = angular.extend($scope.searchform, para);
		$resource('/api/as/csc/auditorder/orderlist', {}, {}).save(para, function (res) {
			if (res.errcode === 0) {
        $scope.objs = res.data.results;
        $scope.bigTotalItems = res.data.totalRecord;
			} else {
				toaster.error({ title: '', body: res.errmsg });
			}
		});
	}

  $scope.loadlist(); 
  
  $scope.getInfo = function(item){
      console.log(item);
      var modalInstance = $modal.open({
        template: require('../views/communityOrderInfo.html'),
        controller: 'communityOrderInfo',
        size: 'lg',
        resolve: {
          'item' : function(){
              return item;
          }
        }
      });

      modalInstance.result.then(function () {
        //load();
      }, function () {
        //$log.info('Modal dismissed at: ' + new Date());
      });
      
  }

	// 审批通过
	$scope.approval = function (obj) {
    if (confirm('确定通过吗?')){
        $resource('/api/as/csc/auditorder/updatestate', {}, {}).save({'code' : obj.code, 'state' : '1'}, function (res) {
          if (res.errcode === 0) {
            toaster.success({ title: '', body: '已审批' });
            $scope.loadlist(); 
          } else {
            toaster.error({ title: '', body: res.errmsg });
          }
        });
    }
  }
  // 办结
	$scope.getThrough = function (obj) {
    if (confirm('确定办结吗?')){
        $resource('/api/as/csc/auditorder/updatestate', {}, {}).save({'code' : obj.code, 'state' : '2'}, function (res) {
          if (res.errcode === 0) {
            toaster.success({ title: '', body: '已办结' });
            $scope.loadlist(); 
          } else {
            toaster.error({ title: '', body: res.errmsg });
          }
        });
    }
  }
  // 不通过
	$scope.notApproval = function (item) {
      var modalInstance = $modal.open({
        template: require('../views/communityBack.html'),
        controller: 'communityBack',
        size: 'xs',
        resolve: {
          'item' : function(){
              return item;
          }
        }
      });

      modalInstance.result.then(function () {
        $scope.loadlist(); 
      }, function () {
        //$log.info('Modal dismissed at: ' + new Date());
      });
  }
  

};